/* eslint-disable @typescript-eslint/no-var-requires */

import { secretId, secretKey } from "../../config/secret";

// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

const FaceidClient = tencentcloud.faceid.v20180301.Client;

const clientConfig = {
  credential: {
    SecretId: secretId,
    SecretKey: secretKey,
  },
  region: "ap-guangzhou",
  profile: {
    httpProfile: {
      endpoint: "faceid.tencentcloudapi.com",
    },
  },
};

const client = new FaceidClient(clientConfig);

// 身份证识别
export function idCardOCR(imgUrl: string) {
  const params = {
    ImageUrl: imgUrl,
  }
  return new Promise((resolve, reject) => {
    client.IdCardOCRVerification(params)
      .then((response: IAnyObject) => {
        resolve(response);
      })
      .catch((error: any) => {
        reject(error);
      })
  })
}

// 身份证核验
export function verify(params: IAnyObject) {
  const {idCard, name} = params;
  const data = {
    IdCard: idCard,
    Name: name
  }
  return new Promise((resolve, reject) => {
    client.IdCardVerification(data)
      .then((response: IAnyObject) => {
        console.log(response, '.....')
        resolve(response);
      })
      .catch((error: any) => {
        console.log(error, '....')
        reject(error);
      })
  })
}
